package liziy.spring.context.annotation;

import liziy.spring.beans.factory.config.BeanDefinition;
import liziy.spring.core.classreading.type.AnnotatedMetadata;

/**
 * 通过BeanDefinition元素初始操作是交给该抽象来进行组装
 * @author Liziy
 * @date 2020/12/17 18:43
 **/
public abstract class AbstractBeanDefinition implements BeanDefinition {
    private String scopeName;
    private String beanClassName;
    private Class<?> beanClass;

    public AbstractBeanDefinition(AnnotatedMetadata metadata) {
        setScope(scopeName);
        setBeanClass(metadata.getBeanClass());
        setBeanClassName(metadata.getBeanName());
    }

    public AbstractBeanDefinition(BeanDefinition definition) {
        setScope(definition.getScope());
        setBeanClass(definition.getBeanClass());
        setBeanClassName(definition.getBeanClassName());
    }

    @Override
    public void setScope(String scopeName) {
        this.scopeName = scopeName;
    }

    @Override
    public String getScope() {
        return this.scopeName;
    }



    @Override
    public Class<?> getBeanClass() {
        return beanClass;
    }

    @Override
    public String getBeanClassName() {
        return beanClassName;
    }

    public void setBeanClassName(String beanClassName) {
        this.beanClassName = beanClassName;
    }

    public void setBeanClass(Class<?> beanClass) {
        this.beanClass = beanClass;
    }

    @Override
    public boolean isPrototype() {
        return SCOPE_PROTOTYPE.equals(this.scopeName);
    }

    @Override
    public boolean isSingleton() {
        return SCOPE_SINGLETON.equals(this.scopeName) || "".equals(this.scopeName);
    }
}
